<%// Copyright 2008 Carnegie Mellon University
// Licensed under the Apache License, Version 2.0 (the "License"); 
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//  
//   http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, 
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.%>

<%@ page language="java" contentType="text/html; charset=UTF-8" %>
<%@ page pageEncoding="UTF-8" %>
<%@ page import="java.sql.*"%>
<%@ page import="edu.cmu.lti.sepia.data.db.SQL"%>
<%@ page import="edu.cmu.lti.sepia.data.db.TaskDAO"%>
<%@ page import="java.util.List"%>
<%@ page import="java.util.ArrayList"%>
<%@ page import="edu.cmu.lti.sepia.infra.topic.model.Task"%>
<%@ page import="edu.cmu.lti.sepia.api.html.ProgressGenerator"%>
<%@ page import="edu.cmu.lti.sepia.servlet.Commons"%>

<%
out.println( Commons.getHeader(request, response, "Exporter", 2) );

// export topic + eval 
boolean isAdmin = request.getParameter("admin")!=null && (Boolean)session.getAttribute("isAdmin");
// export eval
boolean evalMode= request.getParameter("evalMode")!=null;

// otherwise, export topic only
boolean showEval = evalMode || isAdmin; 
boolean showTopic= !evalMode || isAdmin;

StringBuilder sb = new StringBuilder();
try {
  List<Task> tasks;
  if (isAdmin) {
    SQL sql = new SQL();
  	tasks = TaskDAO.getTasks(sql);
  	sql.close();
  } else {
    tasks = new ArrayList<Task>();
    tasks.add(Task.createEmpty());
  }
	for ( Task task : tasks ) {
%>
<%=isAdmin?("<h3>"+task.getFullName()+"</h3><br>"):"" %>
<%
String adminParam = isAdmin?("&taskNameShort="+task.getTaskNameShort()):"";
%>

  <table border="0" cellspacing="0" cellpadding="3" class="datatable">
   <thead>
    <tr>
      <th style="border-bottom:1px solid #000;text-align:center"><b>Data</b></th>
      <th style="border-bottom:1px solid #000;text-align:center"><b>Download Format</b></th>
    </tr>
   </thead>
   <tbody>
<%  
   if (showTopic) { 
%>
    <tr style="height:30px" class="odd">
      <td nowrap><b>Questions (all)</b></td>
      <td>
        <a href="../export/topics2html.jsp?type=q<%=adminParam %>">HTML</a>
        <a href="../io/excel_exporter.html?type=q<%=adminParam %>">EXCEL</a>
        <a href="../export/topics2xml.jsp?type=q<%=adminParam %>">XML</a>
      </td>
    </tr>
    <tr style="height:30px" class="even">
      <td nowrap><b>Questions (selected only)</b></td>
      <td>
        <a href="../export/topics2html.jsp?type=q&selected=1<%=adminParam %>">HTML</a>
        <a href="../io/excel_exporter.html?type=q&selected=1<%=adminParam %>">EXCEL</a>
        <a href="../export/topics2xml.jsp?type=q&selected=1<%=adminParam %>">XML</a>
      </td>
    </tr>
    <tr style="height:30px" class="odd">
      <td nowrap><b>Questions + Answers (selected only)</b></td>
      <td>
        <a href="../export/topics2html.jsp?type=gs&selected=1<%=adminParam %>">HTML</a>
        <a href="../io/excel_exporter.html?type=gs&selected=1<%=adminParam %>">EXCEL</a>
        <a href="../export/topics2xml.jsp?type=gs&selected=1<%=adminParam %>">XML</a>
        <a href="../export/topics2trecAnswerKey.jsp?type=gs&selected=1<%=adminParam %>">TREC AnsKeys</a>
      </td>
    </tr>
<% 
   } 
   if (showEval) { 
%>
    <tr style="height:30px" class="even">
      <td nowrap><b>IR Relevance Judgment</b></td>
      <td>
        <a href="../io/excel_exporter.html?type=qrels<%=adminParam %>">EXCEL</a>
        <a href="../export/qrels.jsp?<%=adminParam %>">TEXT (Qrels)</a>
      </td>
    </tr>
    <tr style="height:30px" class="odd">
      <td nowrap><b>Question Answering Nugget Judgment</b></td>
      <td>
        <a href="../io/excel_exporter.html?type=qa_judgment<%=adminParam %>">EXCEL</a> 
        <a href="../export/nuggets.jsp?<%=adminParam %>">TEXT1 (Nuggets)</a> 
        <a href="../export/qa_judgments.jsp?trgLang=<%=task.getTrgLang()%>&<%=adminParam %>">TEXT2 (Judgments)</a>
      </td>
    </tr>
<% } %>
   </tbody>
  </table>
  <br><br>
<%
	}
	
	if (tasks.size()==0) {
	  %><strong>No data exists to be exported.</strong><%
	} else {
	  %>
	  Selected only = exports only the questions with "done" checkbox marked.<br>
	  <br>
	  Format:
	  <ul>
	  <li>HTML ... HTML table format (easy to quickly check on a web browser).</li>
	  <li>EXCEL ... MS Excel format (.xls).</li>
	  <li>XML ... Standard format with the most detailed information.</li>
	  <li>TREC AnsKeys ... Compatible to factoid answer key format in TREC (exports id + answer nugget only)</li>
	  </ul>
	  <%
	}
} catch ( SQLException e ) {
	e.printStackTrace();
}
out.println(sb);
%>
<br><br>



<%
out.println( Commons.getFooter(request, response) );
%>